struct directional_light {
	vec3 position;			
	vec3 halfplane;			
	vec4 ambient_color;  // make global
	vec4 diffuse_color;
	vec4 specular_color;
};

struct spot_light {
	vec3 position;
	vec3 direction;
	vec3 halfplane; 
	float exponent;
	float angle;
	vec4 ambient_color;  // make global
	vec4 diffuse_color;
	vec4 specular_color;
};


struct material_properties {
	vec4 ambient_color;
	vec4 diffuse_color;
	vec4 specular_color;
	float specular_exponent;
};


uniform material_properties u_material;
//uniform directional_light u_light;


uniform spot_light u_light;


uniform int u_light_num;



uniform vec4 u_global_ambient_color;

uniform mat4 u_mvp_matrix;
uniform mat4 u_modelview_matrix;
uniform mat4 u_inv_modelview_matrix;

uniform float u_lightingMode;

//u_shadowToggle = 1 -> Schatten zeichnen
uniform int u_shadowToggle;
uniform mat4 l_mvp_matrix;


attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec2 a_tc;

varying vec3 v_normal;
varying vec4 v_color;
varying vec2 v_tc;
varying vec3 v_position;
varying float v_cel_intensity;

varying vec4 v_shadow_coord;

const float c_null = 0.0;



void main() {

vec4 temp_normal = u_inv_modelview_matrix * vec4(a_normal, 0.0);

//Gouraud-lighting
if(u_lightingMode == 1.0){

	vec4 light_color;
	vec3 norm_normal = normalize(temp_normal.xyz);

	vec3 norm_lightvector = normalize(u_light.position);
			
	float LdotN = dot(norm_lightvector, norm_normal);
	float HdotN = dot(norm_normal, u_light.halfplane);
	float Irradiance = max(0.0, LdotN);
	vec4 diffuse_term = Irradiance * (u_light.diffuse_color * u_material.diffuse_color);
	vec4 specular_term = pow(max(0.0, HdotN), u_material.specular_exponent) * (u_light.specular_color * u_material.specular_color);
		
	light_color = diffuse_term + specular_term;
	light_color += (u_global_ambient_color * u_material.ambient_color);
	v_color = light_color;
		
	}


	
	//Phong-lighting & Cel-shading
	else if(u_lightingMode == 2.0 || u_lightingMode == 3.0){
		v_normal = temp_normal.xyz;
		}	
	
	
	
	if(u_shadowToggle == 1){
		v_shadow_coord = l_mvp_matrix * a_position;
		}


gl_Position = u_mvp_matrix * a_position;

v_tc = a_tc;
v_position = (u_mvp_matrix * a_position).xyz;

}
